package com.zshy.base.protocol.utils;

import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @author PengQiang
 * @ClassName MapUtil
 * @DateTime 2024/6/25 21:18
 */
public class MapUtil {


    public static SortedMap<String, Object> sortMapByKey(Map<String, Object> map) {
        if (map == null || map.isEmpty()) {
            return new TreeMap<>();
        }

        SortedMap<String, Object> sortedMap = new TreeMap<>();
        map.forEach((key, value) -> {
            if (value instanceof Map<?, ?>) {
                sortedMap.put(key, sortMapByKey((Map<String, Object>) value));
                return;
            }
            sortedMap.put(key, value);

        });
        return sortedMap;
    }
}
